package com.codemart.lanze.config;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;

import com.codemart.lanze.core.freemarker.DirectiveAdvertList;
import com.codemart.lanze.core.freemarker.DirectiveFriendLinkList;

import freemarker.template.Configuration;
import freemarker.template.TemplateModelException;

/**
 * Freemarker模板的配置
 *
 * @author jyk
 */
@org.springframework.context.annotation.Configuration
public class FreemarkerConfig {

	@Autowired
	private Configuration configuration;

	@Autowired
	private DirectiveAdvertList directiveAdvertList;
	@Autowired
	private DirectiveFriendLinkList directiveFriendLinkList;

	@Autowired
	// private DirectiveChannelList directiveChannelList;
	// @Autowired
	// private DirectiveChannelPage directiveChannelPage;
	// @Autowired
	// private DirectiveContentList directiveContentList;
	// @Autowired
	// private DirectiveContentPage directiveContentPage;
	// @Autowired
	// private DirectiveContentView directiveContentView;
	// @Autowired
	// private MethodNextContentTitle methodNextContentTitle;
	// @Autowired
	// private MethodPreContentTitle methodPreContentTitle;
	// @Autowired
	// private MethodEncodeURL methodEncodeURL;

	/**
	 * 指定前台标签
	 *
	 * @throws TemplateModelException
	 */
	@PostConstruct
	public void setSharedVariable() throws TemplateModelException {
		configuration.setSharedVaribles(getSharedVaribles());
	}

	/**
	 * 指定定义标签的标签名和标签对应内容
	 *
	 * @return
	 */
	public Map<String, Object> getSharedVaribles() {
		Map<String, Object> sharedVaribles = new HashMap<>();

		// 广告列表
		sharedVaribles.put("advertList", directiveAdvertList);

		// 友情链接列表
		sharedVaribles.put("friendLinkList", directiveFriendLinkList);

		// // 栏目列表
		// sharedVaribles.put("channelList", directiveChannelList);
		//
		// // 栏目分页
		// sharedVaribles.put("channelPage", directiveChannelPage);
		//
		// // 文章内容列表
		// sharedVaribles.put("contentList", directiveContentList);
		//
		// // 文章内容分页
		// sharedVaribles.put("contentPage", directiveContentPage);
		//
		// // 文章内容详情
		// sharedVaribles.put("content_view", directiveContentView);
		//
		// // 上一篇文章
		// sharedVaribles.put("pre_content_title", methodPreContentTitle);
		//
		// // 下一篇文章
		// sharedVaribles.put("next_content_title", methodNextContentTitle);
		//
		// // 转码后的超链接
		// sharedVaribles.put("encodeURL", methodEncodeURL);

		return sharedVaribles;
	}

}